package com.zht.demo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateConversionExample {
    public static void main(String[] args) {
        String dateString = "Mon Aug 14 15:39:00 CST 2023";

        SimpleDateFormat inputFormat = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date date = inputFormat.parse(dateString);

            // Set the time zone to CST (China Standard Time)
            TimeZone cstTimezone = TimeZone.getTimeZone("Asia/Shanghai");
            outputFormat.setTimeZone(cstTimezone);

            String formattedDate = outputFormat.format(date);
            System.out.println("Formatted Date: " + formattedDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
